﻿using CIS.Common.Entitys;
using CIS.Server.Repository.JobRepository;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CIS.Server.Manager.Job
{
    public class JobManager : IJobManager
    {
        private readonly IJobRepository _jobRepository;

        public JobManager(IJobRepository jobRepository)
        {
            this._jobRepository = jobRepository;
        }
        public async Task<bool> AddJobAsync(JobEntity entity)
        {
            return await _jobRepository.AddAsync(entity);
        }

        public async Task<bool> AddManyJobsAsync(List<JobEntity> entitys)
        {
            return await _jobRepository.AddManyAsync(entitys);
        }

        public async Task<bool> DeleteJobAsync(JobEntity entity)
        {
            return await _jobRepository.DeleteAsync(entity);
        }

        public async Task<bool> DeleteManyJobsAsync(List<JobEntity> entitys)
        {
            return await _jobRepository.DeleteManyAsync(entitys);
        }

        public async Task<List<JobEntity>> GetAllJobsAsync()
        {
            return await _jobRepository.GetAllAsync();
        }

        public async Task<JobEntity> GetJobByGlassCodeAsync(string glassCode)
        {
            return await _jobRepository.GetFirst(j => j.GlassCode == glassCode);
        }

        public async Task<JobEntity> GetJobByJobIdAsync(string jobId)
        {
            return await _jobRepository.GetFirst(j=>j.JobId == jobId);
        }

        public async Task<List<JobEntity>> GetJobsByLotIdAsync(string lotId)
        {
            return await _jobRepository.GetManyAsync(j => j.LotId == lotId);
        }

        public async Task<List<JobEntity>> GetJobsByPortIdAsync(string? portId)
        {
            return await _jobRepository.GetManyAsync(j => j.InPutPortId == portId);
        }

        public async Task<bool> UpdateJobAsync(JobEntity entity)
        {
            return await _jobRepository.UpdateAsync(entity);
        }

        public async Task<bool> UpdateManyJobsAsync(List<JobEntity> entitys)
        {
            return await _jobRepository.UpdateManyAsync(entitys);
        }
    }
}
